package com.xw.framework.base.dao;

import javax.persistence.AttributeConverter;
import javax.persistence.Convert;

@Convert
public class BooleanConverter implements AttributeConverter<Boolean, Integer> {

	@Override
	public Integer convertToDatabaseColumn(Boolean attribute) {
		if(Boolean.TRUE.equals(attribute)){
			return 1;
		}else{
			return 0;
		}
	}

	@Override
	public Boolean convertToEntityAttribute(Integer dbData) {
		return dbData == 1;
	}

}
